//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections;
using OpenLS.Chart.Internals;

namespace OpenLS.Chart.UI
{
    abstract class NonStackedChartLayout: ChartLayout
    {
        private readonly double maximum;
        private readonly int maxIndex;
        private readonly double minimum;
        private readonly bool useRange;

        public override int Count
        {
            get { return maxIndex + 1; }
        }

        public override Bounds GetBounds(int index, int seriesIndex)
        {
            throw new NotImplementedException();
        }

        public override Bounds GetBounds(NumericValue value, Series series, double floor)
        {
            if (useRange)
                return Bounds.Create(floor, value.Value);
            return Bounds.Create(value.Value, value.Value);
        }

        public NonStackedChartLayout(IEnumerable series, bool useRange)
        {
            this.useRange = useRange;
            minimum = double.MaxValue;
            maximum = double.MinValue;
            foreach (Series s in series)
            {
                foreach (NumericValue value in ((INumericValuesProvider) s).GetValues())
                {
                    maxIndex = Math.Max(maxIndex, value.Index);
                    minimum = Math.Min(minimum, value.Value);
                    maximum = Math.Max(maximum, value.Value);
                }
            }
        }
    }
}
